package com.net.framework.help.widget.dot;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.net.framework.help.R;
import com.net.framework.help.utils.UIUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Author：xiaobin.zhang
 * Email：154722566@qq.com
 * Date：2017-09-23 17:03
 * Desc：<--功能描述-->
 */
public class NewDotView extends LinearLayout {
    private ImageView ivIcon;
    private TextView tvDesc;
    private MsgView msgView;
    private ImageView ivArrows;
    private Context mContext;

    public ImageView getIvIcon() {
        return ivIcon;
    }

    public TextView getTvDesc() {
        return tvDesc;
    }

    public MsgView getMsgView() {
        return msgView;
    }


    public NewDotView(Context context) {
        this(context, null, 0);
    }

    public NewDotView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NewDotView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }


    private void initView() {
        View badgeView = View.inflate(mContext, R.layout.layout_arrows_badge_view, null);
        ivIcon = (ImageView) badgeView.findViewById(R.id.iv_icon);
        tvDesc = (TextView) badgeView.findViewById(R.id.tv_desc);
        msgView = (MsgView) badgeView.findViewById(R.id.msgView);
        ivArrows = (ImageView) badgeView.findViewById(R.id.iv_arrows);
        addView(badgeView);
    }


    /**
     * 显示提示的图标
     */
    public void showDotIcon(int drawableRes) {
        ivIcon.setImageResource(drawableRes);
        showDotIcon();
    }

    /**
     * 显示提示的图标
     *
     * @param url                 网络图片地址
     * @param displayImageOptions
     */
    public void showDotIcon(String url, DisplayImageOptions displayImageOptions) {
        ImageLoader.getInstance().displayImage(url, ivIcon, displayImageOptions);
        showDotIcon();
    }

    public void showDotIcon() {
        ivIcon.setVisibility(View.VISIBLE);
    }

    /**
     * 显示文字提示
     *
     * @param descRes
     */
    public void showDotDesc(int descRes) {
        showDotDesc(UIUtils.getString(descRes));
    }


    /**
     * 显示文字提示
     *
     * @param desc
     */
    public void showDotDesc(String desc) {
        tvDesc.setText(desc);
        tvDesc.setVisibility(View.VISIBLE);
    }

    /**
     * 显示未读红点
     */
    public void showDot() {
        UnreadMsgUtils.show(msgView, 0);
    }

    /**
     * 显示未读消息
     *
     * @param num num小于等于0显示红点,num大于0显示数字
     */
    public void showMsg(int num) {
        UnreadMsgUtils.show(msgView, num);
    }

    /**
     * 显示未读消息，放带有符号的tag
     */
    public void showMsg(String content) {
        UnreadMsgUtils.show(msgView, content);
    }

    /**
     * 设置消息泡泡的背景颜色
     *
     * @param backgroundColor
     */
    public void setDotBackgroundColor(int backgroundColor) {
        msgView.setBackgroundColor(backgroundColor);
    }

    /**
     * 是否显示箭头
     *
     * @param isShow
     */
    public void showArrows(boolean isShow) {
        ivArrows.setVisibility(isShow ? View.VISIBLE : View.GONE);
    }
}
